package com.apollow.oschina.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.apollow.oschina.R;
import com.apollow.oschina.base.BaseFragment;
import com.apollow.oschina.base.Global;
import com.apollow.oschina.bean.CollectBean;
import com.apollow.oschina.protocol.SoftProtocol;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Dragon on 2017/1/16.
 */

public class SoftFragment extends BaseFragment {
    @BindView(R.id.rv_collect)
    RecyclerView mRvCollect;
    private SoftProtocol mProtocol;
    private List<CollectBean.FavoriteBean> mFavorites;
    private SoftAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getContext(), R.layout.fragment_soft, null);
        ButterKnife.bind(this, view);
        mAdapter = new SoftAdapter();
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mRvCollect.setLayoutManager(manager);
        mRvCollect.setAdapter(mAdapter);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
    }

    private void initData() {
       /* mProtocol = new SoftProtocol();
        new Thread(new Runnable() {
            @Override
            public void run() {
                mFavorites = mProtocol.getData().getFavorites();
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mAdapter.notifyDataSetChanged();
                    }
                });
            }
        }).start();*/
    }

    public class SoftAdapter extends RecyclerView.Adapter {

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemView = Global.inflate(R.layout.item_fragment_collect, parent);
            ViewHolder holder = new ViewHolder(itemView);
            return holder;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            /*ViewHolder holderview = (ViewHolder) holder;
            holderview.setData(mFavorites.get(position));*/
        }

        @Override
        public int getItemCount() {
            return 3/*mFavorites == null ? 0 : mFavorites.size()*/;
        }

        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.tv_collect)
            TextView mTvCollect;
            ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }


            public void setData(CollectBean.FavoriteBean favoriteBean) {
                //mTvCollect.setText(favoriteBean.getTitle());
            }
        }
    }
}
